package day4;
import java.util.*;
public class Main {
        public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        boolean flg = false;//代表不是小数
        String table = "0123456789ABCDEF";
        StringBuilder ret = new StringBuilder();
        if(m < 0) {
            m = -m;
            flg = true;
        }
        while(m != 0) {
            ret.append(table.charAt(m%n));
            m = m/n;
        }
        if(flg) {
             ret.append("-");
        }
            ret.reverse();
        System.out.println(ret);
    }
}